package com.gufe.controller.admin.club;

import com.gufe.entity.PPTActiveQueryParam;
import com.gufe.entity.PrecollectMember;
import com.gufe.result.PageResult;
import com.gufe.result.Result;
import com.gufe.service.admin.club.ActiveMemberService;
import com.gufe.vo.PPTvo.ActiveMemberVO;
import com.gufe.vo.PPTvo.CollegeCountVO;
import com.gufe.vo.PPTvo.PersonInfoVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/admin/preparatory/active")
@PreAuthorize("hasRole('ADMIN')")
// 管理端预征班现役人员管理
public class ActiveMemberController {


    @Autowired
    private ActiveMemberService activeMemberService;

    /**
     * 分页条件查询现役预征班现役成员信息
     */
    @GetMapping("/page")
    @Cacheable(cacheNames = "activeMembersCache",key = "'getActiveMembers:' + " +
            "T(java.util.Objects).hash(" +
            "#pptActiveQueryParam.page, " +
            "#pptActiveQueryParam.pageSize, " +
            "#pptActiveQueryParam.college, " +
            "#pptActiveQueryParam.gender, " +
            "#pptActiveQueryParam.className, " +
            "#pptActiveQueryParam.name, " +
            "#pptActiveQueryParam.studentId)")
    public Result getActiveMembers(PPTActiveQueryParam pptActiveQueryParam){
        log.info("分页条件查询预征班现役成员：{}",pptActiveQueryParam);
        PageResult<ActiveMemberVO> pageResult = activeMemberService.pageQuery(pptActiveQueryParam);
        return Result.success(pageResult);
    }


    /**
     * 统计各个学院现役成员数
     */
    @GetMapping("/college")
    @Cacheable(cacheNames = "activeMembersCache",key = "'collegeCount'")
    public Result getCollegeCount() {
        log.info("统计各个学院现役成员数");
        List<CollegeCountVO> collegeCountVOList = activeMemberService.getCollegeCount();
        return Result.success(collegeCountVOList);
    }

    /**
     * 获取单个学生的个人信息
     */
    @GetMapping("/member-info/{id}")
    public Result getPersonInfo(@PathVariable Integer id) {
        log.info("根据Id：{}查询社团个人信息...",id);
        PersonInfoVO personInfo =  activeMemberService.getPersonInfo(id);
        return Result.success(personInfo);
    }



}
